<!DOCTYPE html>
<html lang="zh-CN" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>个人常用 Git 命令 | 猿谋人</title>
    <meta name="description" content="个人技术知识库，记录 & 分享个人碎片化、结构化、体系化的技术知识内容。">
    <link rel="preload stylesheet" href="/assets/style.fbdbabc2.css" as="style">
    <script type="module" src="/assets/app.1f95c682.js"></script>
    <link rel="preload" href="/assets/inter-roman-latin.2ed14f66.woff2" as="font" type="font/woff2" crossorigin="">
  <link rel="modulepreload" href="/assets/chunks/framework.41302fb6.js">
  <link rel="modulepreload" href="/assets/chunks/theme.9497cdcb.js">
  <link rel="modulepreload" href="/assets/categories_fragments_2021_个人常用Git命令.md.1e8805ca.lean.js">
  <link rel="icon" href="/favicon.ico">
  <meta name="author" content="buqiyuan">
  <meta name="keywords" content="猿谋人的知识库, 知识库, 博客, buqiyuan">
  <meta name="HandheldFriendly" content="True">
  <meta name="MobileOptimized" content="320">
  <meta name="theme-color" content="#3c8772">
  <meta property="og:type" content="website">
  <meta property="og:locale" content="zh_CN">
  <meta property="og:title" content="猿谋人">
  <meta property="og:description" content="个人技术知识库，记录 &amp; 分享个人碎片化、结构化、体系化的技术知识内容。">
  <meta property="og:site" content="https://blog.buqiyuan.top">
  <meta property="og:site_name" content="猿谋人">
  <meta property="og:image" content="https://blog.buqiyuan.top/logo.jpg">
  <script>var _hmt=_hmt||[];(function(){var e=document.createElement("script");e.src="https://hm.baidu.com/hm.js?f04aacf6aa2e2a9c9174710ff925e139";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)})();</script>
  <script id="check-dark-light">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
  </head>
  <body>
    <div id="app"><div class="Layout" data-v-bacc1dd3><!--[--><!--]--><!--[--><span tabindex="-1" data-v-f2283d62></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-f2283d62> Skip to content </a><!--]--><!----><header class="VPNav" data-v-bacc1dd3 data-v-95f39c38><div class="VPNavBar has-sidebar" data-v-95f39c38 data-v-37e80b00><div class="container" data-v-37e80b00><div class="title" data-v-37e80b00><div class="VPNavBarTitle has-sidebar" data-v-37e80b00 data-v-6d5e4206><a class="title" href="/" data-v-6d5e4206><!--[--><!--]--><!--[--><img class="VPImage logo" src="/logo.png" alt data-v-3cc057b6><!--]--><!--[-->猿谋人<!--]--><!--[--><!--]--></a></div></div><div class="content" data-v-37e80b00><div class="curtain" data-v-37e80b00></div><div class="content-body" data-v-37e80b00><!--[--><!--]--><div class="VPNavBarSearch search" style="--vp-meta-key:&#39;Meta&#39;;" data-v-37e80b00><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg class="DocSearch-Search-Icon" width="20" height="20" viewBox="0 0 20 20" aria-label="search icon"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">搜索文档</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-37e80b00 data-v-73977f53><span id="main-nav-aria-label" class="visually-hidden" data-v-73977f53>Main Navigation</span><!--[--><!--[--><div class="VPFlyout VPNavBarMenuGroup active" data-v-73977f53 data-v-f5e67b47><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-f5e67b47><span class="text" data-v-f5e67b47><!----> 我的分类 <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-f5e67b47><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-f5e67b47><div class="VPMenu" data-v-f5e67b47 data-v-b9038a99><div class="items" data-v-b9038a99><!--[--><!--[--><div class="VPMenuLink" data-v-b9038a99 data-v-110f5163><a class="VPLink link" href="/categories/issues/index.html" data-v-110f5163><!--[-->Bug万象集<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b9038a99 data-v-110f5163><a class="VPLink link active" href="/categories/fragments/index.html" data-v-110f5163><!--[-->&quot;杂碎&quot;逆袭史<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b9038a99 data-v-110f5163><a class="VPLink link" href="/categories/tools/index.html" data-v-110f5163><!--[-->工具四海谈<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/tags/" tabindex="0" data-v-73977f53 data-v-3d76bda5><!--[-->我的标签<!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/archives/" tabindex="0" data-v-73977f53 data-v-3d76bda5><!--[-->我的归档<!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/videos/" tabindex="0" data-v-73977f53 data-v-3d76bda5><!--[-->我的观影院<!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-73977f53 data-v-f5e67b47><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-f5e67b47><span class="text" data-v-f5e67b47><!----> 关于 <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-f5e67b47><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-f5e67b47><div class="VPMenu" data-v-f5e67b47 data-v-b9038a99><div class="items" data-v-b9038a99><!--[--><!--[--><div class="VPMenuLink" data-v-b9038a99 data-v-110f5163><a class="VPLink link" href="/about/blog/" data-v-110f5163><!--[-->关于知识库<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-b9038a99 data-v-110f5163><a class="VPLink link" href="/about/me/#page1" data-v-110f5163><!--[-->关于我<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-37e80b00 data-v-4635adb6><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="toggle dark mode" aria-checked="false" data-v-4635adb6 data-v-66d140a6 data-v-a6e59bae><span class="check" data-v-a6e59bae><span class="icon" data-v-a6e59bae><!--[--><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="sun" data-v-66d140a6><path d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z"></path><path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z"></path><path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z"></path><path d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z"></path><path d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z"></path><path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z"></path><path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z"></path><path d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z"></path><path d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="moon" data-v-66d140a6><path d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z"></path></svg><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-37e80b00 data-v-5f76479f data-v-b340ae52><!--[--><a class="VPSocialLink" href="https://github.com/buqiyuan/buqiyuan.github.io" aria-label="github" target="_blank" rel="noopener" data-v-b340ae52 data-v-ce51fdd1><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>GitHub</title><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg></a><a class="VPSocialLink" href="https://gitee.com/buqiyuan/buqiyuan" aria-label target="_blank" rel="noopener" data-v-b340ae52 data-v-ce51fdd1><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>码云</title><path d="M11.984 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.016 0zm6.09 5.333c.328 0 .593.266.592.593v1.482a.594.594 0 0 1-.593.592H9.777c-.982 0-1.778.796-1.778 1.778v5.63c0 .327.266.592.593.592h5.63c.982 0 1.778-.796 1.778-1.778v-.296a.593.593 0 0 0-.592-.593h-4.15a.592.592 0 0 1-.592-.592v-1.482a.593.593 0 0 1 .593-.592h6.815c.327 0 .593.265.593.592v3.408a4 4 0 0 1-4 4H5.926a.593.593 0 0 1-.593-.593V9.778a4.444 4.444 0 0 1 4.445-4.444h8.296Z"/></svg></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-37e80b00 data-v-b568ad46 data-v-f5e67b47><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-f5e67b47><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="icon" data-v-f5e67b47><circle cx="12" cy="12" r="2"></circle><circle cx="19" cy="12" r="2"></circle><circle cx="5" cy="12" r="2"></circle></svg></button><div class="menu" data-v-f5e67b47><div class="VPMenu" data-v-f5e67b47 data-v-b9038a99><!----><!--[--><!--[--><!----><div class="group" data-v-b568ad46><div class="item appearance" data-v-b568ad46><p class="label" data-v-b568ad46>切换日光/暗黑模式</p><div class="appearance-action" data-v-b568ad46><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="toggle dark mode" aria-checked="false" data-v-b568ad46 data-v-66d140a6 data-v-a6e59bae><span class="check" data-v-a6e59bae><span class="icon" data-v-a6e59bae><!--[--><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="sun" data-v-66d140a6><path d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z"></path><path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z"></path><path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z"></path><path d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z"></path><path d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z"></path><path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z"></path><path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z"></path><path d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z"></path><path d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="moon" data-v-66d140a6><path d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z"></path></svg><!--]--></span></span></button></div></div></div><div class="group" data-v-b568ad46><div class="item social-links" data-v-b568ad46><div class="VPSocialLinks social-links-list" data-v-b568ad46 data-v-b340ae52><!--[--><a class="VPSocialLink" href="https://github.com/buqiyuan/buqiyuan.github.io" aria-label="github" target="_blank" rel="noopener" data-v-b340ae52 data-v-ce51fdd1><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>GitHub</title><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg></a><a class="VPSocialLink" href="https://gitee.com/buqiyuan/buqiyuan" aria-label target="_blank" rel="noopener" data-v-b340ae52 data-v-ce51fdd1><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>码云</title><path d="M11.984 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.016 0zm6.09 5.333c.328 0 .593.266.592.593v1.482a.594.594 0 0 1-.593.592H9.777c-.982 0-1.778.796-1.778 1.778v5.63c0 .327.266.592.593.592h5.63c.982 0 1.778-.796 1.778-1.778v-.296a.593.593 0 0 0-.592-.593h-4.15a.592.592 0 0 1-.592-.592v-1.482a.593.593 0 0 1 .593-.592h6.815c.327 0 .593.265.593.592v3.408a4 4 0 0 1-4 4H5.926a.593.593 0 0 1-.593-.593V9.778a4.444 4.444 0 0 1 4.445-4.444h8.296Z"/></svg></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-37e80b00 data-v-169da333><span class="container" data-v-169da333><span class="top" data-v-169da333></span><span class="middle" data-v-169da333></span><span class="bottom" data-v-169da333></span></span></button></div></div></div></div><!----></header><div class="VPLocalNav" data-v-bacc1dd3 data-v-a57b3302><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a57b3302><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="menu-icon" data-v-a57b3302><path d="M17,11H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h14c0.6,0,1,0.4,1,1S17.6,11,17,11z"></path><path d="M21,7H3C2.4,7,2,6.6,2,6s0.4-1,1-1h18c0.6,0,1,0.4,1,1S21.6,7,21,7z"></path><path d="M21,15H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h18c0.6,0,1,0.4,1,1S21.6,15,21,15z"></path><path d="M17,19H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h14c0.6,0,1,0.4,1,1S17.6,19,17,19z"></path></svg><span class="menu-text" data-v-a57b3302>文章</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a57b3302 data-v-910caf03><button data-v-910caf03>返回顶部</button><!----></div></div><aside class="VPSidebar" data-v-bacc1dd3 data-v-b32353ee><div class="curtain" data-v-b32353ee></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-b32353ee><span class="visually-hidden" id="sidebar-aria-label" data-v-b32353ee> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="group" data-v-b32353ee><section class="VPSidebarItem level-0 collapsible has-active" data-v-b32353ee data-v-84fb9210><div class="item" role="button" tabindex="0" data-v-84fb9210><div class="indicator" data-v-84fb9210></div><h2 class="text" data-v-84fb9210>📑 我的置顶 (2篇)</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-84fb9210><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-84fb9210><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-84fb9210><!--[--><div class="VPSidebarItem level-1 is-link" data-v-84fb9210 data-v-84fb9210><div class="item" data-v-84fb9210><div class="indicator" data-v-84fb9210></div><a class="VPLink link link" href="/categories/fragments/2021/%E4%B8%AA%E4%BA%BA%E5%B8%B8%E7%94%A8%E5%BF%AB%E6%8D%B7%E9%94%AE.html" data-v-84fb9210><!--[--><p class="text" data-v-84fb9210>[1] 个人常用快捷键</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link is-active has-active" data-v-84fb9210 data-v-84fb9210><div class="item" data-v-84fb9210><div class="indicator" data-v-84fb9210></div><a class="VPLink link link" href="/categories/fragments/2021/%E4%B8%AA%E4%BA%BA%E5%B8%B8%E7%94%A8Git%E5%91%BD%E4%BB%A4.html" data-v-84fb9210><!--[--><p class="text" data-v-84fb9210>[2] 个人常用 Git 命令</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-b32353ee><section class="VPSidebarItem level-0 collapsible" data-v-b32353ee data-v-84fb9210><div class="item" role="button" tabindex="0" data-v-84fb9210><div class="indicator" data-v-84fb9210></div><h2 class="text" data-v-84fb9210>2022年 (1篇)</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-84fb9210><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-84fb9210><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-84fb9210><!--[--><div class="VPSidebarItem level-1 is-link" data-v-84fb9210 data-v-84fb9210><div class="item" data-v-84fb9210><div class="indicator" data-v-84fb9210></div><a class="VPLink link link" href="/categories/fragments/2022/CentOS%E5%AE%89%E8%A3%85Docker.html" data-v-84fb9210><!--[--><p class="text" data-v-84fb9210>[1] CentOS 安装 Docker、Docker Compose</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-b32353ee><section class="VPSidebarItem level-0 collapsible has-active" data-v-b32353ee data-v-84fb9210><div class="item" role="button" tabindex="0" data-v-84fb9210><div class="indicator" data-v-84fb9210></div><h2 class="text" data-v-84fb9210>2021年 (2篇)</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-84fb9210><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-84fb9210><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-84fb9210><!--[--><div class="VPSidebarItem level-1 is-link" data-v-84fb9210 data-v-84fb9210><div class="item" data-v-84fb9210><div class="indicator" data-v-84fb9210></div><a class="VPLink link link" href="/categories/fragments/2021/%E4%B8%AA%E4%BA%BA%E5%B8%B8%E7%94%A8%E5%BF%AB%E6%8D%B7%E9%94%AE.html" data-v-84fb9210><!--[--><p class="text" data-v-84fb9210>[1] 个人常用快捷键</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link is-active has-active" data-v-84fb9210 data-v-84fb9210><div class="item" data-v-84fb9210><div class="indicator" data-v-84fb9210></div><a class="VPLink link link" href="/categories/fragments/2021/%E4%B8%AA%E4%BA%BA%E5%B8%B8%E7%94%A8Git%E5%91%BD%E4%BB%A4.html" data-v-84fb9210><!--[--><p class="text" data-v-84fb9210>[2] 个人常用 Git 命令</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-bacc1dd3 data-v-c03735c8><div class="VPDoc has-sidebar has-aside" data-v-c03735c8 data-v-72f0cf66><!--[--><!--]--><div class="container" data-v-72f0cf66><div class="aside" data-v-72f0cf66><div class="aside-curtain" data-v-72f0cf66></div><div class="aside-container" data-v-72f0cf66><div class="aside-content" data-v-72f0cf66><div class="VPDocAside" data-v-72f0cf66 data-v-dbafcf85><!--[--><!--]--><!--[--><!--]--><div class="VPDocAsideOutline" data-v-dbafcf85 data-v-f3ce93eb><div class="content" data-v-f3ce93eb><div class="outline-marker" data-v-f3ce93eb></div><div class="outline-title" data-v-f3ce93eb>目录</div><nav aria-labelledby="doc-outline-aria-label" data-v-f3ce93eb><span class="visually-hidden" id="doc-outline-aria-label" data-v-f3ce93eb> Table of Contents for current page </span><ul class="root" data-v-f3ce93eb data-v-3e931e76><!--[--><!--]--></ul></nav></div></div><!--[--><!--]--><div class="spacer" data-v-dbafcf85></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-72f0cf66><div class="content-container" data-v-72f0cf66><!--[--><!--]--><!----><main class="main" data-v-72f0cf66><div style="position:relative;" class="vp-doc _categories_fragments_2021_%E4%B8%AA%E4%BA%BA%E5%B8%B8%E7%94%A8Git%E5%91%BD%E4%BB%A4" data-v-72f0cf66><div><h1 id="个人常用-git-命令" tabindex="-1">个人常用 Git 命令 <!----> <a class="header-anchor" href="#个人常用-git-命令" aria-label="Permalink to &quot;个人常用 Git 命令 &lt;Badge text=&quot;持续更新&quot; type=&quot;warning&quot; /&gt;&quot;">​</a></h1><h2 id="初始配置" tabindex="-1">初始配置 <a class="header-anchor" href="#初始配置" aria-label="Permalink to &quot;初始配置&quot;">​</a></h2><h3 id="全局配置" tabindex="-1">全局配置 <a class="header-anchor" href="#全局配置" aria-label="Permalink to &quot;全局配置&quot;">​</a></h3><p>在进行版本管理之前，首先需要对 Git 进行用户配置。</p><p>全局配置指的是当前终端上的所有仓库使用该配置，可以在任何位置设置。</p><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 全局配置用户名</span></span>
<span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">config</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--global</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">user.name</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">用户名</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 全局配置用户邮箱</span></span>
<span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">config</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--global</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">user.email</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">用户邮箱</span><span style="color:#89DDFF;">&quot;</span></span></code></pre></div><h3 id="局部配置" tabindex="-1">局部配置 <a class="header-anchor" href="#局部配置" aria-label="Permalink to &quot;局部配置&quot;">​</a></h3><p>局部配置指的是当前终端上的指定仓库使用该配置，需要在指定仓库内进行设置。</p><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 局部配置用户名</span></span>
<span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">config</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">user.name</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">用户名</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 局部配置用户邮箱</span></span>
<span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">config</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">user.email</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">用户邮箱</span><span style="color:#89DDFF;">&quot;</span></span></code></pre></div><h2 id="版本控制相关" tabindex="-1">版本控制相关 <a class="header-anchor" href="#版本控制相关" aria-label="Permalink to &quot;版本控制相关&quot;">​</a></h2><h3 id="初始化仓库" tabindex="-1">初始化仓库 <a class="header-anchor" href="#初始化仓库" aria-label="Permalink to &quot;初始化仓库&quot;">​</a></h3><p>自动创建 master 分支。</p><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">init</span></span></code></pre></div><h3 id="查看工作区状态" tabindex="-1">查看工作区状态 <a class="header-anchor" href="#查看工作区状态" aria-label="Permalink to &quot;查看工作区状态&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">status</span></span></code></pre></div><h3 id="将工作区的修改添加到暂存区" tabindex="-1">将工作区的修改添加到暂存区 <a class="header-anchor" href="#将工作区的修改添加到暂存区" aria-label="Permalink to &quot;将工作区的修改添加到暂存区&quot;">​</a></h3><div class="tip custom-block"><p class="custom-block-title">笔者说</p><p>该命令可执行多次，来实现将多个文件的修改添加到暂存区。另外，如果某个文件在添加到暂存区后又发生了变更，在没有提交到版本库之前，依然需要执行一次该命令。</p></div><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">add</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">文件名1</span><span style="color:#A6ACCD;"> [文件名2...]</span></span></code></pre></div><h3 id="将暂存区的修改提交到版本库" tabindex="-1">将暂存区的修改提交到版本库 <a class="header-anchor" href="#将暂存区的修改提交到版本库" aria-label="Permalink to &quot;将暂存区的修改提交到版本库&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">commit</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-m</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">提交信息</span><span style="color:#89DDFF;">&quot;</span></span></code></pre></div><h3 id="撤销未提交到暂存区的修改" tabindex="-1">撤销未提交到暂存区的修改 <a class="header-anchor" href="#撤销未提交到暂存区的修改" aria-label="Permalink to &quot;撤销未提交到暂存区的修改&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">restore</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">文件名</span></span></code></pre></div><h3 id="撤销暂存区的修改" tabindex="-1">撤销暂存区的修改 <a class="header-anchor" href="#撤销暂存区的修改" aria-label="Permalink to &quot;撤销暂存区的修改&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">restore</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--staged</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">文件名</span></span></code></pre></div><h3 id="查看提交日志" tabindex="-1">查看提交日志 <a class="header-anchor" href="#查看提交日志" aria-label="Permalink to &quot;查看提交日志&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># --oneline 以一行格式显示提交日志</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 查看该文件的提交日志</span></span>
<span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">log</span><span style="color:#A6ACCD;"> [--oneline] </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">文件名</span><span style="color:#89DDFF;">]</span></span></code></pre></div><h3 id="查看操作日志" tabindex="-1">查看操作日志 <a class="header-anchor" href="#查看操作日志" aria-label="Permalink to &quot;查看操作日志&quot;">​</a></h3><p>相比于 <code>git log</code>，reflog 可以查看到所有的操作行为，例如：回退版本······</p><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">reflog</span></span></code></pre></div><h3 id="回退版本" tabindex="-1">回退版本 <a class="header-anchor" href="#回退版本" aria-label="Permalink to &quot;回退版本&quot;">​</a></h3><div class="tip custom-block"><p class="custom-block-title">笔者说</p><p>1、回退版本的数量较少时，可以将 <code>HEAD~回退版本的数量</code> 改为 <code>HEAD^</code> 的写法。</p><p><code>HEAD^</code> 相当于 <code>HEAD~1</code>，<code>HEAD^^</code> 相当于 <code>HEAD~2</code>，依次类推。</p><p>2、回退版本的数量比较多时，建议采用指定 Commit ID 来回退的方法</p></div><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># --hard 回退到相应版本，放弃之前版本的修改</span></span>
<span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">reset</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--hard</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">HEAD~回退版本的数量/HEAD^/Commit</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">ID</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># --soft 回退到相应版本，保留之前版本的修改</span></span>
<span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">reset</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--soft</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">HEAD~回退版本的数量/HEAD^/Commit</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">ID</span></span></code></pre></div><h3 id="修改最后一次提交的信息" tabindex="-1">修改最后一次提交的信息 <a class="header-anchor" href="#修改最后一次提交的信息" aria-label="Permalink to &quot;修改最后一次提交的信息&quot;">​</a></h3><div class="warning custom-block"><p class="custom-block-title">笔者说</p><p>如果你已经将之前本地版本推送到了远程仓库，那么在下一次推送的时候就需要加上 <code>-f</code> 参数了。</p><p><code>git push -f</code></p><p>但是 GitHub 或者公司内的 GitLab 等，默认都是禁止强制推送的，需要设置一下，所以还是多加注意吧。</p></div><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">commit</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--amend</span><span style="color:#A6ACCD;"> [--author=</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">用户名 &lt;用户邮箱&gt;</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;">] </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">-m 提交信息</span><span style="color:#89DDFF;">]</span></span></code></pre></div><h3 id="修改指定提交的信息" tabindex="-1">修改指定提交的信息 <a class="header-anchor" href="#修改指定提交的信息" aria-label="Permalink to &quot;修改指定提交的信息&quot;">​</a></h3><div class="warning custom-block"><p class="custom-block-title">笔者说</p><p>如果你已经将之前本地版本推送到了远程仓库，那么在下一次推送的时候就需要加上 <code>-f</code> 参数了。</p><p><code>git push -f</code></p><p>但是 GitHub 或者公司内的 GitLab 等，默认都是禁止强制推送的，需要设置一下，所以还是多加注意吧。</p></div><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 1.开始（Commit ID 是要修改提交信息的版本的上一个版本的 Commit ID）</span></span>
<span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">rebase</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-i</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">Commit</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">ID</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 2.打开记事本后，将对应提交前的 pick 改为 e 或 edit，保存退出</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 3.进行修订，同上</span></span>
<span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">commit</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--amend</span><span style="color:#A6ACCD;"> [--author=</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">用户名 &lt;用户邮箱&gt;</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;">] </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">-m 提交信息</span><span style="color:#89DDFF;">]</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 4.完成</span></span>
<span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">rebase</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--continue</span></span></code></pre></div><h2 id="远程仓库相关" tabindex="-1">远程仓库相关 <a class="header-anchor" href="#远程仓库相关" aria-label="Permalink to &quot;远程仓库相关&quot;">​</a></h2><h3 id="生成-ssh-key" tabindex="-1">生成 SSH Key <a class="header-anchor" href="#生成-ssh-key" aria-label="Permalink to &quot;生成 SSH Key&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 一路回车即可，最终会在 ${user.home}/.ssh/ 下生成 id_rsa.pub 公钥文件和 id_rsa 私钥文件</span></span>
<span class="line"><span style="color:#FFCB6B;">ssh-keygen</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-t</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">rsa</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-C</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">用户邮箱</span><span style="color:#89DDFF;">&quot;</span></span></code></pre></div><h3 id="添加远程仓库" tabindex="-1">添加远程仓库 <a class="header-anchor" href="#添加远程仓库" aria-label="Permalink to &quot;添加远程仓库&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">remote</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">add</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">origin</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">远程仓库Git地址</span></span></code></pre></div><h3 id="查看远程仓库信息" tabindex="-1">查看远程仓库信息 <a class="header-anchor" href="#查看远程仓库信息" aria-label="Permalink to &quot;查看远程仓库信息&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">remote</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-v</span></span></code></pre></div><h3 id="删除远程仓库" tabindex="-1">删除远程仓库 <a class="header-anchor" href="#删除远程仓库" aria-label="Permalink to &quot;删除远程仓库&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">remote</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">rm</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">origin</span></span></code></pre></div><h3 id="将本地分支推送到远程仓库" tabindex="-1">将本地分支推送到远程仓库 <a class="header-anchor" href="#将本地分支推送到远程仓库" aria-label="Permalink to &quot;将本地分支推送到远程仓库&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 第一次推送时，加上 [-u]，后续不需要加 [-u]</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 如果远程分支名和本地分支名相同，可以省略</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 常见用法：</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#   git push -u origin master</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#   git push origin master</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#   git push</span></span>
<span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">push</span><span style="color:#A6ACCD;"> [-u] </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">远程主机名</span><span style="color:#89DDFF;">]</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">本地分支名</span><span style="color:#89DDFF;">]</span><span style="color:#A6ACCD;">:</span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">远程分支名</span><span style="color:#89DDFF;">]</span></span></code></pre></div><p><strong>【谨慎】如果本地版本和远程版本不一致，可强制推送覆盖：</strong></p><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">push</span><span style="color:#A6ACCD;"> [--force/-f] </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">远程主机名</span><span style="color:#89DDFF;">]</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">本地分支名</span><span style="color:#89DDFF;">]</span><span style="color:#A6ACCD;">:</span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">远程分支名</span><span style="color:#89DDFF;">]</span></span></code></pre></div><h3 id="克隆远程仓库到本地" tabindex="-1">克隆远程仓库到本地 <a class="header-anchor" href="#克隆远程仓库到本地" aria-label="Permalink to &quot;克隆远程仓库到本地&quot;">​</a></h3><div class="tip custom-block"><p class="custom-block-title">笔者说</p><p>适用于本地不存在仓库，远程存在的情况。</p><p>例如：换了电脑，刚开始进入某个项目组等场景。</p></div><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">clone</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">远程仓库Git地址</span></span></code></pre></div><h3 id="拉取远程分支与本地分支合并" tabindex="-1">拉取远程分支与本地分支合并 <a class="header-anchor" href="#拉取远程分支与本地分支合并" aria-label="Permalink to &quot;拉取远程分支与本地分支合并&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 如果远程分支是与当前分支合并，则冒号后面的部分可以省略</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 常见用法：git pull origin</span></span>
<span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">pull</span><span style="color:#A6ACCD;"> [远程主机名] </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">远程分支名</span><span style="color:#89DDFF;">]</span><span style="color:#A6ACCD;">:</span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">本地分支名</span><span style="color:#89DDFF;">]</span></span></code></pre></div><h2 id="多人协作" tabindex="-1">多人协作 <a class="header-anchor" href="#多人协作" aria-label="Permalink to &quot;多人协作&quot;">​</a></h2><h3 id="查看本地分支" tabindex="-1">查看本地分支 <a class="header-anchor" href="#查看本地分支" aria-label="Permalink to &quot;查看本地分支&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">branch</span></span></code></pre></div><h3 id="创建并切换分支" tabindex="-1">创建并切换分支 <a class="header-anchor" href="#创建并切换分支" aria-label="Permalink to &quot;创建并切换分支&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">switch</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-c</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">分支名</span></span></code></pre></div><h3 id="创建分支" tabindex="-1">创建分支 <a class="header-anchor" href="#创建分支" aria-label="Permalink to &quot;创建分支&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">branch</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">分支名</span></span></code></pre></div><h3 id="切换分支" tabindex="-1">切换分支 <a class="header-anchor" href="#切换分支" aria-label="Permalink to &quot;切换分支&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">switch</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">分支名</span></span></code></pre></div><h3 id="将指定分支合并到当前分支" tabindex="-1">将指定分支合并到当前分支 <a class="header-anchor" href="#将指定分支合并到当前分支" aria-label="Permalink to &quot;将指定分支合并到当前分支&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">merge</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">分支名</span></span></code></pre></div><h2 id="标签相关" tabindex="-1">标签相关 <a class="header-anchor" href="#标签相关" aria-label="Permalink to &quot;标签相关&quot;">​</a></h2><h3 id="查看标签" tabindex="-1">查看标签 <a class="header-anchor" href="#查看标签" aria-label="Permalink to &quot;查看标签&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">tag</span></span></code></pre></div><h3 id="打标签" tabindex="-1">打标签 <a class="header-anchor" href="#打标签" aria-label="Permalink to &quot;打标签&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 将指定版本打标签</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 常见用法:</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#   git tag -a v1.0.0 -m &quot;version 1.0.0&quot; b43375</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#   git tag v1.0.0</span></span>
<span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">tag</span><span style="color:#A6ACCD;"> [-a </span><span style="color:#C3E88D;">标签名]</span><span style="color:#A6ACCD;"> [-m </span><span style="color:#C3E88D;">标签信息]</span><span style="color:#A6ACCD;"> [Commit </span><span style="color:#C3E88D;">ID]</span></span></code></pre></div><h3 id="查看指定标签详细信息" tabindex="-1">查看指定标签详细信息 <a class="header-anchor" href="#查看指定标签详细信息" aria-label="Permalink to &quot;查看指定标签详细信息&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">show</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">标签名</span></span></code></pre></div><h3 id="删除标签" tabindex="-1">删除标签 <a class="header-anchor" href="#删除标签" aria-label="Permalink to &quot;删除标签&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">tag</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-d</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">标签名</span></span></code></pre></div><h3 id="将本地标签推送到远程仓库" tabindex="-1">将本地标签推送到远程仓库 <a class="header-anchor" href="#将本地标签推送到远程仓库" aria-label="Permalink to &quot;将本地标签推送到远程仓库&quot;">​</a></h3><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">git</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">push</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">origin</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-tags</span></span></code></pre></div></div></div></main><footer class="VPDocFooter" data-v-72f0cf66 data-v-e4aee8b0><!--[--><!--]--><div class="edit-info" data-v-e4aee8b0><div class="edit-link" data-v-e4aee8b0><a class="VPLink link edit-link-button" href="https://github.com/buqiyuan/buqiyuan.github.io/edit/main/src/categories/fragments/2021/个人常用Git命令.md" target="_blank" rel="noreferrer" data-v-e4aee8b0><!--[--><svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24" class="edit-link-icon" aria-label="edit icon" data-v-e4aee8b0><path d="M18,23H4c-1.7,0-3-1.3-3-3V6c0-1.7,1.3-3,3-3h7c0.6,0,1,0.4,1,1s-0.4,1-1,1H4C3.4,5,3,5.4,3,6v14c0,0.6,0.4,1,1,1h14c0.6,0,1-0.4,1-1v-7c0-0.6,0.4-1,1-1s1,0.4,1,1v7C21,21.7,19.7,23,18,23z"></path><path d="M8,17c-0.3,0-0.5-0.1-0.7-0.3C7,16.5,6.9,16.1,7,15.8l1-4c0-0.2,0.1-0.3,0.3-0.5l9.5-9.5c1.2-1.2,3.2-1.2,4.4,0c1.2,1.2,1.2,3.2,0,4.4l-9.5,9.5c-0.1,0.1-0.3,0.2-0.5,0.3l-4,1C8.2,17,8.1,17,8,17zM9.9,12.5l-0.5,2.1l2.1-0.5l9.3-9.3c0.4-0.4,0.4-1.1,0-1.6c-0.4-0.4-1.2-0.4-1.6,0l0,0L9.9,12.5z M18.5,2.5L18.5,2.5L18.5,2.5z"></path></svg> 不妥之处，敬请雅正<!--]--></a></div><!----></div><div class="prev-next" data-v-e4aee8b0><div class="pager" data-v-e4aee8b0><a class="pager-link prev" href="/categories/fragments/2021/%E4%B8%AA%E4%BA%BA%E5%B8%B8%E7%94%A8%E5%BF%AB%E6%8D%B7%E9%94%AE.html" data-v-e4aee8b0><span class="desc" data-v-e4aee8b0>上一篇</span><span class="title" data-v-e4aee8b0>[1] 个人常用快捷键</span></a></div><div class="has-prev pager" data-v-e4aee8b0><a class="pager-link next" href="/categories/fragments/2022/CentOS%E5%AE%89%E8%A3%85Docker.html" data-v-e4aee8b0><span class="desc" data-v-e4aee8b0>下一篇</span><span class="title" data-v-e4aee8b0>[1] CentOS 安装 Docker、Docker Compose</span></a></div></div></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-bacc1dd3 data-v-11800644><div class="container" data-v-11800644><p class="message" data-v-11800644>Released under the MIT License.</p><p class="copyright" data-v-11800644>Copyright © 2023-present buqiyuan</p></div></footer><!--[--><!--]--></div></div>
    <script>__VP_HASH_MAP__ = JSON.parse("{\"categories_fragments_2021_个人常用git命令.md\":\"1e8805ca\",\"categories_fragments_2021_个人常用快捷键.md\":\"8d1225a9\",\"categories_fragments_2022_centos安装docker.md\":\"7708bad4\",\"archives_index.md\":\"18ef748b\",\"categories_fragments_index.md\":\"8e75883a\",\"categories_issues_2022_vite开发环境ui框架库加载提速不同ui库的写法.md\":\"8296c03c\",\"categories_issues_index.md\":\"fb964abe\",\"categories_tools_2021_quartz快速入门.md\":\"811edab3\",\"categories_tools_index.md\":\"94566b9c\",\"index.md\":\"b74bf964\",\"tags_index.md\":\"4fffe6de\",\"about_blog_index.md\":\"0f85a16e\",\"about_me_index.md\":\"c62dcafb\"}")
__VP_SITE_DATA__ = JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"猿谋人\",\"description\":\"个人技术知识库，记录 & 分享个人碎片化、结构化、体系化的技术知识内容。\",\"base\":\"/\",\"head\":[],\"appearance\":true,\"themeConfig\":{\"nav\":[{\"text\":\"我的分类\",\"items\":[{\"text\":\"Bug万象集\",\"link\":\"/categories/issues/index\",\"activeMatch\":\"/categories/issues/\"},{\"text\":\"\\\"杂碎\\\"逆袭史\",\"link\":\"/categories/fragments/index\",\"activeMatch\":\"/categories/fragments/\"},{\"text\":\"工具四海谈\",\"link\":\"/categories/tools/index\",\"activeMatch\":\"/categories/tools/\"}],\"activeMatch\":\"/categories/\"},{\"text\":\"我的标签\",\"link\":\"/tags/\",\"activeMatch\":\"/tags/\"},{\"text\":\"我的归档\",\"link\":\"/archives/\",\"activeMatch\":\"/archives/\"},{\"text\":\"我的观影院\",\"link\":\"/videos/\",\"activeMatch\":\"/videos/\"},{\"text\":\"关于\",\"items\":[{\"text\":\"关于知识库\",\"link\":\"/about/blog/\",\"activeMatch\":\"/about/blog/\"},{\"text\":\"关于我\",\"link\":\"/about/me/#page1\",\"activeMatch\":\"/about/me/\"}],\"activeMatch\":\"/about/\"}],\"sidebar\":{\"/categories/issues/\":[{\"text\":\"2022年 (1篇)\",\"items\":[{\"text\":\"[1] Vite开发环境UI框架库加载提速不同UI库的写法\",\"link\":\"/categories/issues/2022/Vite开发环境UI框架库加载提速不同UI库的写法\",\"date\":{}}],\"collapsed\":false}],\"/categories/fragments/\":[{\"text\":\"📑 我的置顶 (2篇)\",\"items\":[{\"text\":\"[1] 个人常用快捷键\",\"link\":\"/categories/fragments/2021/个人常用快捷键\",\"date\":{}},{\"text\":\"[2] 个人常用 Git 命令\",\"link\":\"/categories/fragments/2021/个人常用Git命令\",\"date\":{}}],\"collapsed\":false},{\"text\":\"2022年 (1篇)\",\"items\":[{\"text\":\"[1] CentOS 安装 Docker、Docker Compose\",\"link\":\"/categories/fragments/2022/CentOS安装Docker\",\"date\":{}}],\"collapsed\":false},{\"text\":\"2021年 (2篇)\",\"items\":[{\"text\":\"[1] 个人常用快捷键\",\"link\":\"/categories/fragments/2021/个人常用快捷键\",\"date\":{}},{\"text\":\"[2] 个人常用 Git 命令\",\"link\":\"/categories/fragments/2021/个人常用Git命令\",\"date\":{}}],\"collapsed\":true}],\"/categories/tools/\":[{\"text\":\"2021年 (1篇)\",\"items\":[{\"text\":\"[1] Quartz 快速入门\",\"link\":\"/categories/tools/2021/Quartz快速入门\",\"date\":{}}],\"collapsed\":false}]},\"logo\":\"/logo.png\",\"outline\":{\"level\":\"deep\",\"label\":\"目录\"},\"darkModeSwitchLabel\":\"切换日光/暗黑模式\",\"sidebarMenuLabel\":\"文章\",\"returnToTopLabel\":\"返回顶部\",\"lastUpdatedText\":\"最后更新\",\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"editLink\":{\"pattern\":\"https://github.com/buqiyuan/buqiyuan.github.io/edit/main/src/:path\",\"text\":\"不妥之处，敬请雅正\"},\"search\":{\"provider\":\"local\",\"options\":{\"locales\":{\"root\":{\"translations\":{\"button\":{\"buttonText\":\"搜索文档\",\"buttonAriaLabel\":\"搜索文档\"},\"modal\":{\"noResultsText\":\"无法找到相关结果\",\"resetButtonTitle\":\"清除查询条件\",\"footer\":{\"selectText\":\"选择\",\"navigateText\":\"切换\"}}}}}}},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/buqiyuan/buqiyuan.github.io\"},{\"icon\":{\"svg\":\"<svg role=\\\"img\\\" viewBox=\\\"0 0 24 24\\\" xmlns=\\\"http://www.w3.org/2000/svg\\\"><title>码云</title><path d=\\\"M11.984 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.016 0zm6.09 5.333c.328 0 .593.266.592.593v1.482a.594.594 0 0 1-.593.592H9.777c-.982 0-1.778.796-1.778 1.778v5.63c0 .327.266.592.593.592h5.63c.982 0 1.778-.796 1.778-1.778v-.296a.593.593 0 0 0-.592-.593h-4.15a.592.592 0 0 1-.592-.592v-1.482a.593.593 0 0 1 .593-.592h6.815c.327 0 .593.265.593.592v3.408a4 4 0 0 1-4 4H5.926a.593.593 0 0 1-.593-.593V9.778a4.444 4.444 0 0 1 4.445-4.444h8.296Z\\\"/></svg>\"},\"link\":\"https://gitee.com/buqiyuan/buqiyuan\"}],\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2023-present buqiyuan\"},\"articleMetadataConfig\":{\"author\":\"猿谋人\",\"authorLink\":\"/about/me\",\"showViewCount\":true},\"copyrightConfig\":{\"license\":\"署名-相同方式共享 4.0 国际 (CC BY-SA 4.0)\",\"licenseLink\":\"http://creativecommons.org/licenses/by-sa/4.0/\"},\"commentConfig\":{\"type\":\"gitalk\",\"showComment\":true},\"footerConfig\":{\"showFooter\":true,\"icpRecordCode\":\"津ICP备2022005864号-2\",\"publicSecurityRecordCode\":\"津公网安备12011202000677号\",\"copyright\":\"Copyright © 2019-2023 buqiyuan\"}},\"locales\":{},\"scrollOffset\":90,\"cleanUrls\":false}")</script>
    
  </body>
</html>